<template>
  <div class="welcome">
    <h1>首页</h1>
    <el-card class="card">
      <el-row :gutter="20">
        <el-col :span="8">
          <el-card shadow="hover">
            <h1>管理员总数 1</h1>
            <div class="headerIconBox">
              <i class="headerIcon el-icon-s-tools"></i>
            </div>
          </el-card>
        </el-col>
        <el-col :span="8">
          <el-card shadow="hover">
            <h1>用户总数 {{ showUserAll.count || "???" }}</h1>
            <div class="headerIconBox">
              <i class="headerIcon el-icon-user-solid"></i>
            </div>
          </el-card>
        </el-col>
        <el-col :span="8">
          <el-card shadow="hover">
            <h1>图书总数 {{ showBookList.count || "???" }}</h1>
            <div class="headerIconBox">
              <i class="headerIcon el-icon-s-management"></i>
            </div>
          </el-card>
        </el-col>
        <el-col :span="24">
          <!-- 用户卡片区域 -->
          <el-card shadow="hover" class="userCard">
            <el-avatar
              class="userimg"
              :src="
                loginUserInfo.userimg
                  ? loginUserInfo.userimg
                  : 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png'
              "
            ></el-avatar>
            <el-divider></el-divider>
            <el-row class="userRow">
              <el-col>
                昵称：
                {{ loginUserInfo.nickname }}
              </el-col>
              <el-col>
                用户名：
                {{ loginUserInfo.username }}
              </el-col>
              <el-col>
                性别：
                {{ loginUserInfo.sex }}
              </el-col>
              <el-col>
                手机号：
                {{ loginUserInfo.phone }}
              </el-col>
              <el-col>
                邮箱：
                {{ loginUserInfo.mail }}
              </el-col>
              <i class="el-icon-s-grid"></i>
            </el-row>
          </el-card>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
export default {
  data() {
    return {
      loginUserInfo: {},
      // 用户数量
      userSum: "",
      // 图书数量
      bookSum: "",
    };
  },
  created() {
    this.$store.dispatch("getBookClazz");
    this.getLoginUser();
    this.$store.dispatch("getUserAll", {
      queryInfo: {
        currentPage: 1, // 当前页码
        pagesize: 10, // 每页显示的行数
      },
    });
    this.$store.dispatch("getBookList");
    // this.$store.dispatch("getBookList");
  },
  computed: {
    ...mapGetters([
      "showLogName",
      "showLoginUser",
      "showBookList",
      "showUserAll",
    ]),
  },
  methods: {
    async getLoginUser() {
      this.$store.dispatch("getUsrInfo", this.showLogName);
      this.loginUserInfo = JSON.parse(localStorage.getItem("loginUser"));
    },
  },
};
</script>
<style lang="less" scoped>
.welcome {
  > .card {
    margin-top: 20px;

    .el-row {
      margin-top: 20px;
      .el-card {
        margin-top: 20px;
        .headerIconBox {
          position: relative;
          top: -36px;
          left: 410px;
          width: 50px;
          height: 50px;
          background-color: #fff;
          border-radius: 10px;
          .headerIcon {
            font-size: 50px;
          }
        }
        .headerIconBox:hover {
          background-color: #000;
        }
        .headerIcon:hover {
          color: #fff;
        }
      }
      .userCard {
        .userimg {
          width: 150px;
          height: 150px;
          border-radius: 50%;
          margin-left: 50%;
          transform: translateX(-50%);
        }
        .userRow {
          .el-col {
            margin-top: 20px;
            .el-tag {
              font-size: 18px;
            }
          }
          .el-icon-s-grid {
            position: absolute;
            right: 20px;
            font-size: 180px;
            color: #d3dce6;
          }
        }
      }
      .comment {
        max-height: 62vh;
        margin-top: 20px;
        overflow: auto;
        .el-card:nth-child(2n + 0) {
          background-color: rgb(236, 236, 236);
        }
      }
    }
  }
}
</style>